package Aptech.Service;

import Aptech.DAL.MgBuilts;
import Aptech.DAL.MgRoom;
import Aptech.DALInterface.BuiltsInterface;
import Aptech.DALInterface.RoomInterface;
import HibernateMappingPoJo.Rooms;
import java.util.Iterator;
import java.util.List;

public class SV_Rooms {

	RoomInterface mgRoom;
	BuiltsInterface mgBuilt;

	public SV_Rooms() {
		mgRoom = new MgRoom();
		mgBuilt = new MgBuilts();
	}

	public Rooms[] getAllRoom() {
		List list = mgRoom.getAllRoom();
		String nameBuit = "";

		Rooms[] listRoom = new Rooms[list.size()];
		if (list != null) {
			Iterator iter = list.iterator();
			int i = 0;
			while (iter.hasNext()) {
				Rooms tptd = (Rooms) iter.next();
				nameBuit = mgBuilt.getBuiltsByID(tptd.getIdBuilt()).getName();
				tptd.setIdBuilt(nameBuit);
				listRoom[i] = tptd;
				i++;
			}
		}
		return listRoom;
	}

	public void addRoom(Rooms room) {
		mgRoom.addRoom(room);
	}

	public void editRoom(Rooms room) {
		mgRoom.editRoom(room);
	}

	public void deleteRoom(String id) {
		mgRoom.deleteRoom(id);
	}

	public Rooms getRoomByID(String id) {
		return mgRoom.getRoomByID(id);
	}
	
	public Rooms[] getRoomByBuilt(String idBuilt){
		List list = mgRoom.getRoomByBuilt(idBuilt);
		String nameBuit = "";

		Rooms[] listRoom = new Rooms[list.size()];
		if (list != null) {
			Iterator iter = list.iterator();
			int i = 0;
			while (iter.hasNext()) {
				Rooms tptd = (Rooms) iter.next();
				nameBuit = mgBuilt.getBuiltsByID(tptd.getIdBuilt()).getName();
				tptd.setIdBuilt(nameBuit);
				listRoom[i] = tptd;
				i++;
			}
		}
		return listRoom;
	}
}
